var async = require('async')
var autodb = require('../../db/auto.db')
var logger = require('../../logger')
var emit = require('../../emit')

function onsocket(socket, data) {
    if(data.id == null){
        console.log('id is null');
        return;
    }
    autodb.readfile(data.isMusic, data.id, (err, data, filename) => {
        if (err) {
            console.log(err);
        } else {
            if (data.isMusic) {
                console.log('download-music', filename);
                emit.send(socket, 'download-music', { wav: data, name: filename });

            } else {
                console.log('download-sound', filename);
                emit.send(socket, 'download-sound', { wav: data, name: filename });
            }
        }
    })
}

module.exports = {
    onsocket
}